using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using fitnesse.slim;
using java.util;
using NDesk.Options;
using util;

namespace FitNesse4Net
{
    public class DotNetSlimService : SlimService
    {
        public DotNetSlimService(int port, SlimServer slimServer) : base(port, slimServer)
        {
            instance = this;
        }

        public static void Execute(DotNetSlimFactory slimFactory, params string[] args)
        {
            if (ParseCommandLine(args))
            {
                startWithFactory(args, slimFactory);
            }
            else
            {
                Console.Error.WriteLine("Invalid command line arguments:" + Arrays.asList(args));
            }
        }

        private static bool ParseCommandLine(IEnumerable<string> args)
        {
            verbose = args.Any(a => a.Equals("-v"));
            
            if(int.TryParse(args.Last(), out port))
            {
                return true;
            }

            return false;
        }
    }
}